﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NH_Entity;
using NH_Factory;
namespace QHY.Controllers
{
    public class AccountController : Controller
    {
        //
        // GET: /Account/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LogOn()
        {
            return View();
        }
        [HttpPost]
        public ActionResult LogOn(QHY_User model)
        {
            if (ModelState.IsValid)
            {
                QHY_User user;
                using (var session = NHibernateHelper.sessionFactory.OpenSession())
                {
                    user = session.QueryOver<QHY_User>().Where(p => p.UserName == model.UserName && p.Password == model.Password).SingleOrDefault();
                }

                if (user != null)
                {
                    Session["UserName"] = user.UserName;
                    Session["Password"] = user.Password;
                    return RedirectToAction("Index", "Default", new { area = "Admin" });
                }
                else
                {
                    ModelState.AddModelError("UserName", "用户名或密码错误！");
                }


            }
            return View(model);
        }
        public ActionResult Register()
        {

            return View();
        }
    }
}
